<?php
namespace Admin\Controller;
use Think\Controller;
use Common\BaseController;
use Common\Common\Log;
class IndexController extends BaseController {
    public function index(){
        $res=M("node")->where("status=1")->select();
        $arr=array();
        foreach($res as $k=>$v)
        {
            if($v['pid']==0)
            {
                $arr[]=$res[$k];
            }
        }
        foreach($arr as $k=>$v)
        {
           foreach($res as $key=>$val){
               if($val['pid']==$v['id']){
                   $val['controller']=empty($val['controller'])?"Index":$val['controller'];
                   $val['action']=empty($val['action'])?"index":$val['action'];
                   $val['url']=$val['controller'].'/'.$val['action'];
                   $arr[$k]['son'][]=$val;
               }
           }
        }
         $this->assign("nav",$arr);
        $this->display();
    }
    public function errors()
    {
        $this->display();
    }
    public function back(){
        $name=session('user.userName');
        session('user',null);
        $content=$name.'退出登陆';
        Log::write2($content);
        $this->showMsg('亲爱的 '.$name.' 用户,欢迎再来！','success','index');
    }
}